package com.example.demo.finitestatemachine.transition;

import com.example.demo.finitestatemachine.event.LiftEvent;
import com.example.demo.finitestatemachine.event.LiftEventCodeEnums;
import com.example.demo.finitestatemachine.state.LiftState;

/**
 * @author liyuncong
 * @version 1.0
 * @file AbstractLiftTransition
 * @brief AbstractLiftTransition
 * @details AbstractLiftTransition
 * @date 2022-12-28
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-12-28                  liyuncong          Created
 */
public abstract class AbstractLiftTransition {

    /**
     * 触发当前状态
     */
    private final LiftState currentState;

    /**
     * 触发后状态
     */
    private final LiftState nextState;

    /**
     * 触发事件
     */
    private final LiftEventCodeEnums eventCode;


    public AbstractLiftTransition(
        LiftState currentState,
        LiftState nextState,
        LiftEventCodeEnums eventCode
    ) {
        this.currentState = currentState;
        this.nextState = nextState;
        this.eventCode = eventCode;
    }

    public LiftState execute(LiftEvent event) {
        if (this.doExecute(event)) {
            return this.nextState;
        } else {
            return null;
        }
    }

    protected abstract boolean doExecute(LiftEvent event);

    public LiftState getCurrentState() {
        return currentState;
    }

    public LiftState getNextState() {
        return nextState;
    }

    public LiftEventCodeEnums getEventCode() {
        return eventCode;
    }
}
